<%@ page import="java.sql.Statement" import="java.sql.ResultSet" import="java.sql.Connection" import="java.util.*" %> 
<%@page import="connection.DBConnection"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Customer Invoice wise </title>
<script type="text/javascript">
function sub()
{
	var t=0.0;
	
		var a=document.getElementById("innamt").value;
	var b=document.getElementById("amtadjust").value;
	
	var c=parseFloat(a)-parseFloat(b);
	document.getElementById("balamt").value=c;
	
	t=parseFloat(t)+parseFloat(b);
	
	if(b>a)
		{
		var d=b-a;
		document.getElementById("advance").value=d;
		
		
		}	
	document.getElementById("total").value=t;
	}
	</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<link href="globalCSS.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">


<style>
	.hidden 
	{
		display : none
	}
</style>

</head>
<body>
<h2 align="center"> Customer Invoice wise outstanding</h2>
<form name="bankledgerreport" method="get" action=CustomerInvoiceServlet>

<table align="center" border=5 width=700>
<tr><th>Date</th>
<th>Invoice Number</th>
<th>Invoice Amount</th>
<th>Amount Adjusted</th>
<th>Balance Amount</th></tr>



<%  DBConnection dbc=new DBConnection();
			Connection con=dbc.getNewConnection();
			Statement st = null;
			ResultSet rs = null;
			String selectedcustcode = (String) request.getAttribute("custcode");
			///int count=1;
			double debtors=0, creditors=0, cashbank=0, fixedassets=0, other=0, capital=0, otherexpenses=0, sellingandmarketing=0, salaryandwages=0, administrativecharges=0, provision=0, unsecuredloans=0, securedloans=0, investments=0, closingstock=0, openingstock=0, loansandadvances=0, indirectincome=0, bankchargesandinterest=0, depreciation=0; //trial balance
			
			double bal=0.0,in=0.0,adj=0.0;
			
			String dte="",nm="",cd="",inn="";
			List li=new ArrayList();
			%>
			
			<%! int cnt=0; %>
			<%
			
			
			%>
			
			
			
			<%
			try
			{
				  st=con.createStatement() ;
				  rs=st.executeQuery("select count(*) from salesinvoiceoutstanding where ccode= '"+selectedcustcode+"'");
				  while(rs.next())
				  {
					  cnt=rs.getInt(1);
					  
				  }
				%>
				  <%
					  if(cnt>0)
					  {
						  
						  rs=st.executeQuery("select innum,date,svname,ccode, balance,adjamount,scred from salesinvoiceoutstanding where ccode='"+selectedcustcode+"'  group by innum");
						  while(rs.next())
						  {
							  
							  inn=rs.getString(1);
								dte=rs.getString(2);
								nm=rs.getString(3);
								cd=rs.getString(4);
								 in=rs.getDouble(5);
								 adj=rs.getDouble(6);
								 int cred=rs.getInt(7);
								
								%>
								
								<input type=hidden name=cname value="<%=nm%>"/>
				  <input type=hidden name=ccd value="<%=cd%>"/>
				<input type=hidden name=cred value="<%=cred%>"/>
			 <tr>
			 <td><input type=hidden id=dte name=dte value="<%=dte %>"/><%=dte %></td>
			 
			 <td><input type=hidden id=inn name=inn value="<%=inn %>"/><%=inn %></td>
			<td><input type=hidden  name=innamt id=innamt value="<%=in %>"/><%=in %></td>
			 <td><input type=text name=amtadjust id=amtadjust value="0" onblur="sub()" /></td>
			 <td><input type=text name=balamt id=balamt value="<%=in %>" /></td>
			 
			  </tr>
								
								<%
								
							  }
						  }
					  else{
					  rs=st.executeQuery("select innum,date,scname,ccode, stota,scredlim from salesvoucher2 where ccode='"+selectedcustcode+"'  group by innum;");
					  
				
				while(rs.next()){
					inn=rs.getString(1);
				dte=rs.getString(2);
				nm=rs.getString(3);
				cd=rs.getString(4);
				
				 in=rs.getDouble(5);
				 
				 int cred1=rs.getInt(6);
				
				
				 		%>
				<input type=hidden name=cname value="<%=nm%>"/>
				  <input type=hidden name=ccd value="<%=cd%>"/>
				<input type=hidden name=cred value="<%=cred1%>"/>
			 <tr>
			 <td><input type=hidden id=dte name=dte value="<%=dte %>"/><%=dte %></td>
			 
			 <td><input type=hidden id=inn name=inn value="<%=inn %>"/><%=inn %></td>
			<td><input type=hidden  name=innamt id=innamt value="<%=in %>"/><%=in %></td>
			 <td><input type=text name=amtadjust id=amtadjust value="0" onblur="sub()" /></td>
			 <td><input type=text name=balamt id=balamt value="<%=in %>" /></td>
			 
			  </tr>
<% }}%>


<%
	
			}
			   catch(Exception e)
			   {} %>
			   <tr><td></td><td>Advanced Received</td><td></td><td><input type=text name=advance id=advance value="0"/></td><td></td></tr>
			   <tr><td></td><td>Total</td><td></td><td><input type=text name=total id=total value="0"/></td><td></td></tr>
			   
			
			   
 </table>

    <script>
$('tr').each(function () {
	  a = $(this).children('td:eq(2)').text();
	  if (a == "0.0") {
	      $(this).addClass('hidden');
	  }
	});
</script>

 <br><br>
<center> <input type=submit value=Save></center>
		</form>	   
			  
</body>


</html>